package com.nxk.modules.content.web;

import com.nxk.modules.content.entity.ConService;
import com.nxk.modules.content.service.ConServiceService;
import com.nxk.modules.exception.ResultEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/a/content/service")
public class ConServiceController {
    
    
    @Autowired
    private ConServiceService conServiceService;


    /**
     * 保存数据接口
     *
     * @param conService
     * @return
     */
    @RequiresPermissions("content:service:edit")
    @PutMapping("/save")
    public ResultEntity save(@Validated ConService conService) {
        boolean save = conServiceService.save(conService);
        return save ? ResultEntity.success(conServiceService.getById(conService.getId())) : ResultEntity.fail();
    }


    /**
     * 更新数据接口
     *
     * @param conService
     * @return
     */
    @RequiresPermissions("content:service:edit")
    @PostMapping("/update")
    public ResultEntity update(@Validated ConService conService) {
        boolean save = conServiceService.save(conService);
        return save ? ResultEntity.success(conServiceService.getById(conService.getId())) : ResultEntity.fail();
    }


    /**
     * 修改数据状态接口
     *
     * @param conService
     * @return
     */
    @RequiresPermissions("content:service:edit")
    @PostMapping("/updateStatus")
    public ResultEntity updateStatus(ConService conService) {
        boolean save = conServiceService.save(conService);
        return save ? ResultEntity.success(conServiceService.getById(conService.getId())) : ResultEntity.fail();
    }


    /**
     * 根据id获取单条数据接口
     *
     * @param conService
     * @return
     */
    @RequiresPermissions("content:service:view")
    @GetMapping("/get")
    public ResultEntity get(ConService conService) {
        return ResultEntity.success(conServiceService.getById(conService.getId()));
    }


    /**
     * 查询分页数据接口
     *
     * @param conService
     * @return
     */
    @RequiresPermissions("content:service:view")
    @PostMapping("list")
    public ResultEntity list(ConService conService) {
        return ResultEntity.success(conServiceService.page(conService));
    }

    /**
     * 根据id物理删除数据接口
     *
     * @param conService
     * @return
     */
    @RequiresPermissions("content:service:edit")
    @DeleteMapping("delete")
    public ResultEntity delete(ConService conService) {
        boolean delete = conServiceService.deleteById(conService.getId());
        return delete ? ResultEntity.success() : ResultEntity.fail();
    }
}
